from src.common.base_method import BaseMethod


class BasePage(BaseMethod):
    """
    公共的元素或组件
    """

    def login(self, username, password):
        """
        用户登录
        Args:
            username: 用户名
            password: 密码
        """
        self.send_keys('name', 'login', username)
        self.send_keys('name', 'password', password)
        self.click('css', 'button')

    def open_menu(self, menu):
        """
        打开导航菜单栏
        Args:
            menu: 菜单名
        """
        self.click('part_link_text', menu)

    def click_btn(self, btn_name, tag='span'):
        """
        点击按钮
        Args:
            btn_name: 按钮名称
            tag: 标签名
        """
        if tag == 'span':
            self.click('xpath', '//span[text()="{}"]'.format(btn_name))
        elif tag == 'a':
            self.click('xpath', '//a[contains(text(), "{}")]'.format(btn_name))

    @property
    def toast(self):
        """
        获取提示信息
        """
        return self.get_text('css', 'div[class="notice"]')
